package com.sixth.statistics.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sixth.core.entity.CheckResult;
import com.sixth.core.vo.R;
import com.sixth.statistics.mapper.CheckResultMapper;
import com.sixth.statistics.service.CheckResultService;
import com.sixth.statistics.vo.CheckResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @program: six-hospital-system
 * @description:
 * @author: 朱永奇
 * @create: 2024-08-19 15:02
 **/
@Service
public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult> implements CheckResultService {
    @Autowired
    private CheckResultMapper checkResultMapper;
    /**
     * 检查项目分页统计
     * @param checkResultVo
     * @return
     */
    @Override
    public R<IPage<CheckResult>> selectAll(CheckResultVo checkResultVo) {
        //创建分页
        IPage<CheckResult> page = new Page<>(checkResultVo.getPageNum(),checkResultVo.getPageSize());
        //创建查询条件
        QueryWrapper<CheckResult> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(checkResultVo.getCheckItemName())){
            wrapper.like("check_item_name",checkResultVo.getCheckItemName());
        }
        if (StringUtils.hasText(checkResultVo.getPatientName())){
            wrapper.like("patient_name",checkResultVo.getPatientName());
        }
        if(checkResultVo.getDateRange()!=null&&checkResultVo.getDateRange().size()==2){
            wrapper.between("create_time",checkResultVo.getDateRange().get(0),checkResultVo.getDateRange().get(1));
        }
        wrapper.eq("result_status" ,1);
        IPage<CheckResult> checkResults = checkResultMapper.selectPage(page, wrapper);
        return R.ok(checkResults);
    }
}
